package com.hxk.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hxk.pojo.User;
/**
 * springboot整合thymeleaf
 * @author Cactus
 */
@Controller
public class UserController {

	@RequestMapping("/showUser")
	public String showUsers(Model model) {
		List<User> users = new ArrayList<User>();
		users.add(new User(1, "张三", 20));
		users.add(new User(1, "李四", 21));
		users.add(new User(1, "王五", 22));
		model.addAttribute("users", users);
		return "userlist";
	}
	
	@RequestMapping("/thobj")
	public String thObj(Model model) {
		model.addAttribute("key", null);
		model.addAttribute("msg", "thymeleaf hello word");
		model.addAttribute("date", new Date());
		return "thobj";
	}
	
	@RequestMapping("/thbasic")
	public String thbasic(Model model, HttpServletRequest request) {
		model.addAttribute("sex", "男");
		model.addAttribute("id", "2");
		List<String> list = new ArrayList<String>();
		list.add("1");
		list.add("2");
		list.add("3");
		list.add("4");
		model.addAttribute("list", list);
		Map<String, String> map = new HashMap<String, String>();
		map.put("u1", "张三");
		map.put("u2", "李四");
		map.put("u3", "王五");
		model.addAttribute("map", map);
		request.setAttribute("req", "req值");
		request.getSession().setAttribute("ses", "ses的值");
		request.getSession().getServletContext().setAttribute("app", "app的值");
		return "thbasic";
	}
	
	@RequestMapping("/thurl")
	public String thurl() {
		return "thurl";
	}
	
	@RequestMapping("/show")
	public String show(int id, String name) {
		System.out.println(id+">>>"+name);
		return "thurl";
	}
	
	@RequestMapping("pach/{id}/show")
	public String show1(@PathVariable int id, String name) {
		System.out.println(id+">>111111>"+name);
		return "thurl";
	}
}